import { Component, EventEmitter, Input, OnInit, Output, TemplateRef, ViewChild } from '@angular/core';
import { NzModalRef, NzMessageService } from 'ng-zorro-antd';
import { SFSchema } from '@delon/form';
import { MenuService } from '../../menu-manage/menu.service';
import { UtilService } from '@core/services/util.service';
import { ApiService } from '@core/services/api';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-server-edit',
  templateUrl: './server-edit.component.html',
  styles: []
})
export class ServerEditComponent implements OnInit {
  @Input() type : 0 | 1;
  @Input() set _param(value){
    if(!value) return;
    this.param=value;
  }
  param:object;
  showForm:boolean=false;
  schema: SFSchema = {
    properties: {
      type: {
        type: 'string',
        title: '类型',
      },
      serverName: {
        type: 'string',
        title: '名称',
      },
      serverValue: {
        type: 'string',
        title: '值',
      },
      roleRemark: {
        type: 'string',
        title: '备注',
      },
    },
    required: ['type', 'serverName', 'serverValue'],
  };
  constructor(
    private msg: NzMessageService,
    private modalRef: NzModalRef,
    private menu: MenuService,
    private util: UtilService,
    private api: ApiService,
    private http: HttpClient
    ) { }

  ngOnInit() {
    this.showForm=true;
  }

    // 确定编辑功能
    formSubmit(data) {
      const url = this.type === 0 ? this.api.role.add.url : this.api.role.update.url;
      const method = this.type === 0 ? this.api.role.add.method : this.api.role.update.method
      this.http.request<any>(method, url,  { }).subscribe(res => {
        console.log(res)
        if (res.status === '200' || res.status === '201') {
          this.msg.success('操作成功');
          this.modalRef.triggerOk();
        } else {
          this.msg.error(res.message)
        }
      })
  
    }
}
